package cn.yanxiaohui.service.web.controller;

import cn.yanxiaohui.data.entity.BookMark;
import cn.yanxiaohui.service.web.service.BookMarkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 书签控制器
 * @author yanxh
 *
 */
@Controller
@RequestMapping("/bookMark")
public class BookMarkController extends BaseController{
	
	/** 视图统一前缀 **/
	private final static String PREFIX = "bookMark/";
	
	@Autowired
	BookMarkService bookMarkService;
	
	/**
	 * 书签管理首页
	 */
	@RequestMapping(value = "/index", method = RequestMethod.GET)
	public String index(ModelMap model) {
		Map<String, Object> params = new HashMap<String, Object>();
		List<BookMark> bookMarkList = bookMarkService.listByParams(params);
		model.addAttribute("bookMarkList", bookMarkList);
		return PREFIX + "index";
	}
	
	
	/**
	 * 书签详情
	 */
	@RequestMapping(value = "/detail/{id}", method = RequestMethod.GET)
	public String detail(ModelMap model, @PathVariable Long id) {
		BookMark bookMark = bookMarkService.bookMarkById(id);
		model.addAttribute("bookMark", bookMark);
		return PREFIX + "detail";
	}


}
